import java.util.*;

/** This class contains static operations for generating graphs. For now,
    it only contains a few simple operations for generating city graphs.
    @author Ian Helmke, Dan King
*/
public class GraphGenerator {

  /** Creates a city graph based on the given ArrayList of Capitals
      and ArrayList of Strings. This method is intended to allow for
      integration of the data from the Capitals.java file into our map.
  */
  public static Graph makeCapitalGraph(ArrayList<City> cities, 
                                       ArrayList<String> states,
                                       List<List<String>> neighborList) {
    // First, instantiate a new graph.
    Graph<String, City, Route> usaGraph = new Graph<String, City, Route>("United States");

    // Now, we need to add the cities that we have to it.
    for (City city : cities) {
      INode<City, Route> cityNode = new Node<City, Route>(city);
      
      usaGraph.addNode(city.getState(), cityNode);
    }
    
    // All cities are now in the graph. NOW, we need to add the links to other cities
    // to the graph. This is a challenge, because all we have is a silly little two
    // character designation for each city. HOWEVER, it becomes much easier once we
    // realize that our key to find the cities is, in fact, that two character designation.
    for (int i = 0; i < states.size(); i++) {
      INode<City, Route> currentCity = usaGraph.getNode(states.get(i));
      
      for (String linkedCity : neighborList.get(i)) {
        INode<City, Route> destination = usaGraph.getNode(linkedCity);
        
        // @TODO - make a better name for routes - generate randomly?
        Route info = new Route("Connection", Math.random() * 2,
                               currentCity.getInfo(), destination.getInfo());

        currentCity.addLink(new Link<Route, City>(destination, info));
      }
    }
    
    return usaGraph;
  }

}
